﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PerformanceAssessment.Models
{
    public static class StringExtensions
    {
        /// <summary>
        /// Truncates a string to a specified length and add ... if it's truncated
        /// </summary>
        /// <param name="value">String</param>
        /// <param name="maxLength">Max length</param>
        /// <returns>Truncated string</returns>
        public static string Truncate(this string value, int maxLength)
        {
            if (value != null)
                return value.Length <= maxLength ? value : string.Format("{0}...", value.Substring(0, maxLength));
            return null;
        }
    }
}